//
//  YouHuiQuanCell.m
//  HubeiHotel
//
//  Created by LiBenCan on 17/11/21.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "YouHuiQuanCell.h"

@implementation YouHuiQuanCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = 0;
    }
    return self;
}

- (void)loadCell
{
    //背景图片
    _backImageV = [TomamaUI createImageView:CGRectMake(10*screenW_6, 10*screenW_6,SCREENW-20*screenW_6,100*screenW_6) backGroundImageV:@"juan"];
    [self.contentView addSubview:_backImageV];
    [_backImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10*screenW_6);
        make.top.equalTo(self.contentView).offset(10*screenW_6);
        make.width.equalTo(@(SCREENW-20*screenW_6));
        make.height.equalTo(@(100*screenW_6));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(0*screenW_6);
    }];
    
    //价格
    _bigLab = [TomamaUI createLabel:CGRectMake(10*screenW_6,20*screenW_6, (SCREENW-20*screenW_6)*0.33, 30*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:30*screenW_6] textColor:[UIColor whiteColor] text:@"¥50"];
    [_backImageV addSubview:_bigLab];
    
    //种类
    _kindLab = [TomamaUI createLabel:CGRectMake(10*screenW_6,50*screenW_6, (SCREENW-20*screenW_6)*0.33, 35*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor whiteColor] text:@"优惠券"];
    [_backImageV addSubview:_kindLab];
    
    
    //范围
    _rangeLab = [TomamaUI createLabel:CGRectMake((SCREENW-20*screenW_6)*0.43,20*screenW_6, (SCREENW-20*screenW_6)*0.56,20*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:16*screenW_6] textColor:[UIColor whiteColor] text:@"武汉丽顿酒店（光谷店）"];
    [_backImageV addSubview:_rangeLab];
    
    //有效期
    _timeLab = [TomamaUI createLabel:CGRectMake((SCREENW-20*screenW_6)*0.43,45*screenW_6, (SCREENW-20*screenW_6)*0.56,16*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor colorWithHexString:@"#CBDFF6"] text:@"有效期：2017—10-26"];
    [_backImageV addSubview:_timeLab];
    
    //使用／有效
    _statusLab = [TomamaUI createLabel:CGRectMake((SCREENW-20*screenW_6)*0.43,65*screenW_6, (SCREENW-20*screenW_6)*0.56,16*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor colorWithHexString:@"#FDD6D3"] text:@"未使用"];
    [_backImageV addSubview:_statusLab];
    _statusLab.hidden = YES;
    
    
    //领取按钮
    _ChooseLab = [TomamaUI createLabel:CGRectMake(SCREENW-77*screenW_6,65*screenW_6,45*screenW_6,24*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor whiteColor] text:@"领取"];
    [_ChooseLab.layer setCornerRadius:8*screenW_6];
    _ChooseLab.layer.masksToBounds = YES;
    _ChooseLab.layer.borderWidth = 0.5;
    _ChooseLab.layer.borderColor = [[UIColor whiteColor]CGColor];
    [_backImageV addSubview:_ChooseLab];
 
}

-(void)loadCellWithData:(NSDictionary *)data
{
    
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    _dataDic = data;
    //背景图片
    _backImageV = [TomamaUI createImageView:CGRectMake(10*screenW_6, 10*screenW_6,SCREENW-20*screenW_6,100*screenW_6) backGroundImageV:@"juan"];
    [self.contentView addSubview:_backImageV];
    [_backImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10*screenW_6);
        make.top.equalTo(self.contentView).offset(10*screenW_6);
        make.width.equalTo(@(SCREENW-20*screenW_6));
        make.height.equalTo(@(100*screenW_6));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(0*screenW_6);
    }];
    _backImageV.userInteractionEnabled = YES;
    
    //价格
    _bigLab = [TomamaUI createLabel:CGRectMake(10*screenW_6,20*screenW_6, (SCREENW-20*screenW_6)*0.33, 30*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:30*screenW_6] textColor:[UIColor whiteColor] text:[NSString stringWithFormat:@"￥%@",data[@"denomination"]]];
    [_backImageV addSubview:_bigLab];
    
    //种类
    _kindLab = [TomamaUI createLabel:CGRectMake(10*screenW_6,50*screenW_6, (SCREENW-20*screenW_6)*0.33, 35*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor whiteColor] text:@"优惠券"];
    [_backImageV addSubview:_kindLab];
    
    
    //范围
    _rangeLab = [TomamaUI createLabel:CGRectMake((SCREENW-20*screenW_6)*0.43,20*screenW_6, (SCREENW-20*screenW_6)*0.56,20*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:16*screenW_6] textColor:[UIColor whiteColor] text:@"武汉丽顿酒店（光谷店）"];
    [_backImageV addSubview:_rangeLab];
    
    //有效期
    _timeLab = [TomamaUI createLabel:CGRectMake((SCREENW-20*screenW_6)*0.43,45*screenW_6, (SCREENW-20*screenW_6)*0.56,16*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor colorWithHexString:@"#CBDFF6"] text:[NSString stringWithFormat:@"有效期：%@",data[@"effectiveDate"]]];
    [_backImageV addSubview:_timeLab];
    
//    //使用／有效
    _statusLab = [TomamaUI createLabel:CGRectMake((SCREENW-20*screenW_6)*0.43,65*screenW_6, (SCREENW-20*screenW_6)*0.56,16*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor colorWithHexString:@"#FDD6D3"] text:@"未使用"];
    [_backImageV addSubview:_statusLab];
    _statusLab.hidden = YES;
    //领取按钮
    _ChooseLab = [TomamaUI createLabel:CGRectMake(SCREENW-77*screenW_6,65*screenW_6,45*screenW_6,24*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor whiteColor] text:@"领取"];
    [_ChooseLab.layer setCornerRadius:8*screenW_6];
    _ChooseLab.layer.masksToBounds = YES;
    _ChooseLab.layer.borderWidth = 0.5;
    _ChooseLab.layer.borderColor = [[UIColor whiteColor]CGColor];
    [_backImageV addSubview:_ChooseLab];
    _ChooseLab.userInteractionEnabled = YES;
    [_ChooseLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getCoupon)]];
}

-(void)getCoupon
{
    if (_block) {
        _block(_dataDic[@"id"]);
    }
}

-(void)setDataDic:(NSDictionary *)dataDic
{
    if ([dataDic[@"status"] integerValue]== 0) {
        _backImageV.image = [UIImage imageNamed:@"juan"];
        _statusLab.text = @"未使用";
        _ChooseLab.text = @"使用";
        _ChooseLab.hidden = NO;
        _statusLab.hidden = NO;
        _statusLab.textColor = _timeLab.textColor = [UIColor colorWithHexString:@"#95bCED"];
    }else  if ([dataDic[@"status"] integerValue]== 1) {
        _backImageV.image = [UIImage imageNamed:@"juan_red"];
        _statusLab.text = @"已使用";
        _statusLab.hidden = NO;
        _statusLab.textColor = _timeLab.textColor = [UIColor colorWithHexString:@"#FDD6D3"];
        _ChooseLab.hidden = YES;
    }else  if ([dataDic[@"status"] integerValue]== 2) {
        _backImageV.image = [UIImage imageNamed:@"juan_hui"];
        _statusLab.text = @"已过期";
        _statusLab.hidden = NO;
        _statusLab.textColor = _timeLab.textColor = [UIColor colorWithHexString:@"#DEDDDD"];
        _ChooseLab.hidden = YES;
    }
}
@end
